package com.example.demo.common;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

/**
 * excel 针对业务的解析 校验 配置 与业务一对一 .
 *
 * @author Dax
 * @see CellRule
 * @since 16 :15  2018/5/17
 */
public class ExcelConfig {
    //  实际行excel索引 cxcel行号-1
    private int rowNum;
    //    字段名称  按照顺序
    private String[] columnNames;
    //    字段校验规则   key 为字段columnNames 对应 字段名称
    private Map<String, CellRule> rules;
    // 数据指向core 层的服务类
    private String coreService;
    // 数据指向core 层的服务方法
    private String coreMethod;
    /**
     * {@link AddrLvlEnum}
     */
    private AddrLvlEnum addrLvlEnum;
    /**
     * Gets rowNum.
     *
     * @return the rowNum
     */
    public int getRowNum() {
        return rowNum;
    }

    /**
     * Sets rowNum.
     *
     * @param rowNum the rowNum
     */
    public void setRowNum(int rowNum) {
        this.rowNum = rowNum;
    }

    /**
     * Get column names string [ ].
     *
     * @return the string [ ]
     */
    public String[] getColumnNames() {
        return columnNames;
    }

    /**
     * Sets column names.
     *
     * @param columnNames the column names
     */
    public void setColumnNames(String[] columnNames) {
        this.columnNames = columnNames;
    }

    /**
     * Gets rules.
     *
     * @return the rules
     */
    public Map<String, CellRule> getRules() {
        return rules;
    }

    /**
     * Sets rules.
     *
     * @param rules the rules
     */
    public void setRules(Map<String, CellRule> rules) {
        this.rules = rules;
    }

    public String getCoreService() {
        return coreService;
    }

    public void setCoreService(String coreService) {
        this.coreService = coreService;
    }

    public String getCoreMethod() {
        return coreMethod;
    }

    public void setCoreMethod(String coreMethod) {
        this.coreMethod = coreMethod;
    }

    public AddrLvlEnum getAddrLvlEnum() {
        return addrLvlEnum;
    }

    public void setAddrLvlEnum(AddrLvlEnum addrLvlEnum) {
        this.addrLvlEnum = addrLvlEnum;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ExcelConfig)) return false;
        ExcelConfig config = (ExcelConfig) o;
        return getRowNum() == config.getRowNum() &&
                Arrays.equals(getColumnNames(), config.getColumnNames()) &&
                Objects.equals(getRules(), config.getRules()) &&
                Objects.equals(getCoreService(), config.getCoreService()) &&
                Objects.equals(getCoreMethod(), config.getCoreMethod()) &&
                getAddrLvlEnum() == config.getAddrLvlEnum();
    }

    @Override
    public int hashCode() {

        int result = Objects.hash(getRowNum(), getRules(), getCoreService(), getCoreMethod(), getAddrLvlEnum());
        result = 31 * result + Arrays.hashCode(getColumnNames());
        return result;
    }

    @Override
    public String toString() {
        return "{" +
                "rowNum:" + rowNum +
                ", columnNames:" + Arrays.toString(columnNames) +
                ", rules:" + rules +
                ", coreService:" + coreService +
                ", coreMethod:" + coreMethod +
                ", addrLvlEnum:" + addrLvlEnum +
                '}';
    }
}
